package cn.hesion;
/**
 * ClassName: NumOrderMap <br/>
 * Description: <br/>
 * date: 2021/2/1 18:21<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @program: homework1_1
 * @description: 数据排序Map端
 * @author: hesion
 * @create: 2021-02-01 18:21
 **/
public class NumOrderMap extends Mapper<LongWritable, Text, IntWritable, IntWritable> {
    // 只是一个填充数，无意义
    IntWritable i = new IntWritable(1);
    // 用于包装读取出来的数字
    IntWritable k = new IntWritable();
    /**
     * @return void
     * @Author hst
     * @Description //TODO Hadoop在进行shuffle操作时，会对KEY进行归并排序，因此我们住需要讲读取到的数据作为KEY，即可完成排序操作
     * @Date 18:26 2021/2/1
     * @Param [key, value, context]
     **/
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 读取出文字
        String line = value.toString();
        // 转换成数字，不做转换，无法利用shuffle进行排序
        Integer integer = new Integer(line);
        int num = integer.intValue();
        k.set(num);
        // 读取每一行，将读到的值，直接作为key
        context.write(k, i);
    }
}
